#region [file: EmpresaDAL.cs, author: Lucas Bittencourt]
// File:    EmpresaDAL.cs
// Author:  Lucas Bittencourt
// Created: segunda-feira, 7 de novembro de 2011 20:48:48
// Purpose: Defines dao implementation class for class Empresa
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of IEmpresaDAL interface
   /// </summary>
   public class EmpresaDAL : NHibernateDALBase,  IEmpresaDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Empresa
      /// </summary>     
      public List<Empresa> GetEmpresaList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Empresa)));
      }
      
      /// <summary>
      /// Get the instances of Empresa from index firstResult to index maxResult
      /// </summary>
      public List<Empresa> GetEmpresaList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Empresa), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Empresa according its primary key instance.
      /// </summary>
      public Empresa Load(EmpresaPK empresaPK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "EmpIdEmpresa" };
         object[] values = new object[] { empresaPK.EmpIdEmpresa };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Empresa), cs);
         return (((list != null) && (list.Count > 0)) ? (Empresa)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Empresa according its example instance.
      /// </summary>
      public List<Empresa> QueryByExample(Empresa empresa)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Empresa), empresa));
      }

      /// <summary>
      /// Query the instances of Empresa according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Empresa> QueryByExample(Empresa empresa, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Empresa), empresa, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Empresa
      /// </summary>
      public void Insert(Empresa empresaObject)
      {
         base.Save(empresaObject);
      }
      
      /// <summary>
      /// Update the instances of Empresa
      /// </summary>
      public void Update(Empresa empresaObject)
      {
         base.Update(empresaObject);
      }
      
      /// <summary>
      /// Delete the instances of Empresa
      /// </summary>
      public void Delete(Empresa empresaObject)
      {
         base.Delete(empresaObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Empresa according to its attribute empNmEmpresa
      /// </summary>
      public List<Empresa> FindByEmpNmEmpresa(string empNmEmpresa) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EmpNmEmpresa", empNmEmpresa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Empresa), cs));
      }
      
      /// <summary>
      /// Find the instances of Empresa according to its attribute empNmEmpresa, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Empresa> FindByEmpNmEmpresa(string empNmEmpresa, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EmpNmEmpresa", empNmEmpresa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Empresa), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Empresa according to its attribute empNuCnpj
      /// </summary>
      public List<Empresa> FindByEmpNuCnpj(string empNuCnpj) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EmpNuCnpj", empNuCnpj));
         return ConvertToGenericList(base.FindByCriterions(typeof(Empresa), cs));
      }
      
      /// <summary>
      /// Find the instances of Empresa according to its attribute empNuCnpj, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Empresa> FindByEmpNuCnpj(string empNuCnpj, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("EmpNuCnpj", empNuCnpj));
         return ConvertToGenericList(base.FindByCriterions(typeof(Empresa), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Empresa> ConvertToGenericList(IList empresas)
      {
         List<Empresa> empresaList = new List<Empresa>();
         foreach (Empresa empresa in empresas)
         {
             empresaList.Add(empresa);
         }
         return empresaList;
      }      
   }
}